<template>
    <view>
        <status-bar :title="title"></status-bar>
        <Search :placeTxt="placeTxt" @Search="searchData"></Search>
        <view class="Wrapper">
            <view class="list" v-for="(item, index) in pageData" :key="index" @click="$Means.Sublevel(item)">
                <image :src="$imgUrls(item.img)" mode="aspectFit" class="Img"></image>
                <text class="title ellipsis">{{ item.title }}</text>
            </view>
        </view>
        <emptys v-if="!pageData.length"></emptys>
    </view>
</template>

<script>
    import { mapState } from 'vuex';
    import api from './api.js';
    import Search from '@/classification/components/Search.vue';
    export default {
        components: {
            Search
        },

        data() {
            return {
                title: '',
                placeTxt: '',
                pt: '1', // 1图片分类  2纯文字  3左右结构 4文章列表 5查询结果页 6详情页
                type: '2', // 1分类  2标签  3内容列表  4内容详情
                list_id: 0, // 37803
                label_id: 0, //1342
                page: 1,
                limit: 10,
                id: '', // 详情ID
                pageData: [],
                getMore: true
            };
        },
        onLoad(opt) {
            if (opt.pt) this.pt = opt.pt;
            if (opt.type) this.type = opt.type;
            if (opt.list_id) this.list_id = opt.list_id;
            if (opt.label_id) this.label_id = opt.label_id;
            this.init();
        },
        methods: {
            async init() {
                let reuesetObj = {
                    pt: this.pt,
                    type: this.type,
                    list_id: this.list_id,
                    label_id: this.label_id,
                    id: this.id,
                    // query_text: this.query_text,
                    page: this.page,
                    limit: this.limit
                };
                const requsetResult = await api.dataQuery(reuesetObj);
                this.title = requsetResult.title;
                this.placeTxt = requsetResult.query_text;
                const result = requsetResult.list || [];
                this.page == 1 ? (this.pageData = result) : (this.pageData = [...this.pageData, ...result]);
                if (result.length < this.limit) this.getMore = false;
            },
            searchData(e) {
                this.toUrl(`mediaSearch?list_id=${this.list_id}&label_id=${this.label_id}&val=${e}`);
            }
        },
        computed: {
            ...mapState(['totalHeight', 'System'])
        },
        onReachBottom() {
            if (!this.getMore) return;
            this.page++;
            this.init();
        }
    };
</script>

<style lang="scss">
    page {
        background-color: $page;
        padding-bottom: 24rpx;
    }
</style>
<style lang="scss" scoped>
    .Wrapper {
        width: 710rpx;
        background-color: #fff;
        margin: 20rpx auto;
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        border-radius: 10rpx;
        gap: 0;
        .list {
            height: 240rpx;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            border-right: 1px solid $page;
            border-bottom: 1px solid $page;
            .Img {
                width: 140rpx;
                height: 140rpx;
            }
            .title {
                color: #333;
                font-size: 30rpx;
                margin-top: 10rpx;
                text-align: center;
            }
        }
    }
</style>
